package com.pi.shisan.test.encoder;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

public class MsgEncoder extends MessageToByteEncoder {
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, Object o, ByteBuf byteBuf) throws Exception {
        if (o instanceof byte[]) {
            byteBuf.writeBytes((byte[])o);
        } else if (o instanceof Short) {
            byteBuf.writeShort(((Short) o).shortValue());
        } else if (o instanceof Integer) {
            byteBuf.writeShort(((Integer) o).shortValue());
        } else if (o instanceof Long) {
            byteBuf.writeLong(((Long) o).longValue());
        }
    }
}
